package com.sc.nft.dao;

import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.sc.nft.entity.*;
import com.sc.nft.entity.dto.CollectionChipDTO;
import com.sc.nft.entity.vo.ActivityAwardSaveDetailsVO;
import com.sc.nft.entity.vo.CollectionChipVO;
import com.sc.nft.mapper.ActivityAwardMapper;
import com.sc.nft.mapper.CollectionChipMapper;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.annotations.Param;
import org.springframework.stereotype.Repository;

import java.math.BigDecimal;
import java.util.Date;
import java.util.List;

@Slf4j
@Repository
public class CollectionChipDao extends ServiceImpl<CollectionChipMapper, CollectionChip> {

    public CollectionChip getCollectionChipById(Long id) {
        LambdaQueryWrapper<CollectionChip> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(CollectionChip::getId,id);
        return getOne(wrapper);
    }

    public Page<CollectionChipVO> getCollectionChipPage(CollectionChipDTO collectionChipDTO) {
        return baseMapper.getCollectionChipPage(collectionChipDTO.toMp(),collectionChipDTO.getName(), DateUtil.format(collectionChipDTO.getStartTime(),"yyyy-MM-dd HH:mm:ss"),DateUtil.format(collectionChipDTO.getEndTime(),"yyyy-MM-dd HH:mm:ss"));
    }

    public Integer checkProductBind(Long productId) {
        LambdaQueryWrapper<CollectionChip> lambdaQueryWrapper = new LambdaQueryWrapper<>();
        lambdaQueryWrapper.eq(CollectionChip::getProductId, productId);
        return count(lambdaQueryWrapper);
    }
}
